package com.yc.project2_knn.group2;

import com.yc.project2_knn.BankMarketingLoaader;
import com.yc.project2_knn.bean.BankMarketing;

import java.util.List;

public class Test3_Main {
    public static void main(String[] args) throws InterruptedException {
        //System.out.println("项目执行路径: "+ System.getProperty("user.dir"));//D:\software\ideaIU\IntelliJ IDEA 2023.2.5\ideaprojects\gitee_thread
        //看发布路径  不是src  D:\software\ideaIU\IntelliJ IDEA 2023.2.5\ideaprojects\gitee_thread\src\main\java\com\yc\project2_knn\data
        String trainpath =System.getProperty("user.dir")+ "\\src\\main\\java\\com\\yc\\project2_knn\\data\\bank.data";
//        System.out.println("训练集的路径："+trainpath);
        List<BankMarketing> train = BankMarketingLoaader.load(trainpath);//训练集
        //System.out.println("训练集大小："+train.size());
        //测试集
        String testpath = System.getProperty("user.dir")+ "\\src\\main\\java\\com\\yc\\project2_knn\\data\\bank.test";
        List<BankMarketing> test = BankMarketingLoaader.load(trainpath);//训练集
        //System.out.println("测试集大小："+test.size());
        //knn的k的确定
        int k=10;
        // java Test2_ _main
        if( args!=null&args.length>0){
            k=Integer.parseInt( args[0] );
        }

        //// 2059 * 12线程( 39129 )
        //定义两个变量存测试集
        int success=0, mistakes=0;
        int numThread =Runtime.getRuntime().availableProcessors();
        System.out.println("线程数量"+numThread);
        ParallerroupKnnClassfier classify = new ParallerroupKnnClassfier(k, numThread, true, train);

        Long start,end;
        start= System.currentTimeMillis();

        //循环测试集中的每一条，调用这个模型进行预测
        for (BankMarketing testData: test) {
            //tag就是模型预测的类别
            String tag=classify.classify(testData);
            if( tag.equals( testData. getTag())){
                success++ ;
            }else {
                mistakes++;
            }
        }
        end = System.currentTimeMillis();
        System.out.println("按cpu的核数 生成任务的版本：计算矩阵乘法的时间："+(end-start));
        System.out.println("正确数为："+success+"   ,错误数字为："+mistakes+ " 正确率为 ："+ ((double)success/(success+mistakes)));
    }
}
